package edu.zut.software.identity.Service.impl;

import edu.zut.software.identity.Repository.StuGradeRepository;
import edu.zut.software.identity.Service.StuGradeService;
import edu.zut.software.identity.domain.StuGrade;
import edu.zut.software.identity.domain.StuMajor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class StuGradeServiceImpl implements StuGradeService {
    private StuGradeRepository stuGradeRepository;
    @Autowired
    public void setStuGradeRepository(StuGradeRepository stuGradeRepository) {
        this.stuGradeRepository = stuGradeRepository;
    }

    @Override
    public void deleteById(String id) {
        stuGradeRepository.deleteById(id);
    }

    @Override
    public void save(StuGrade stuGrade) {
        stuGradeRepository.save(stuGrade);
    }

    @Override
    public StuGrade findById(String id) {
        return stuGradeRepository.findById(id).orElseThrow(RuntimeException::new);
    }

    @Override
    public List<StuGrade> findAll() {
        return stuGradeRepository.findAll();
    }

    @Override
    public Page<StuGrade> findAll(Integer page, Integer pageSize) {
        Pageable pageable = PageRequest.of(page, pageSize);
        Page<StuGrade> pageInfo = stuGradeRepository.findAll(pageable);
        return pageInfo;
    }

    @Override
    public List<StuGrade> getGradeInfoByMajorId(String Id) {
        return stuGradeRepository.getGradeInfoByMajorId(Id);
    }
}
